package chap06;

import javafx.scene.control.TextField;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

class FoucsEvent1 extends JFrame {
    JTextField textField;
     public static void main(String[] args) {
         new FoucsEvent1();
     }
     FoucsEvent1(){
         FocusEvent_Example();
     }
     public void  FocusEvent_Example(){
         setTitle("焦点事件示例");
         setBounds(100, 100, 500, 375);
         getContentPane().setLayout(new FlowLayout());
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         final JLabel label = new JLabel();
         label.setText("出生日期");
         getContentPane().add(label);
         textField = new JTextField();
         textField.setColumns(10);
         textField.addFocusListener(new TextFieldFocus());
         getContentPane().add(textField);
         final JButton button = new JButton();
         button.setText("确定");
         getContentPane().add(button);
         setVisible(true);
     }
    class TextFieldFocus implements FocusListener {
        public void focusGained(FocusEvent event) {
            textField.setText("");
        }

        public void focusLost(FocusEvent event) {
            textField.setText("2008-8-8");
        }
    }
}


